package com.example.controller.admin;

import com.example.dto.OrdersEmployeeDTO;
import com.example.dto.OrdersPageQueryDTO;
import com.example.dto.OrdersRejectionDTO;
import com.example.entity.OrdersEmployee;
import com.example.result.Result;
import com.example.service.OrdersEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (OrdersEmployee)表控制层
 *
 * @author makejava
 * @since 2024-04-16 16:13:36
 */
@RestController
@RequestMapping("/admin/ordersEmployee")
@Slf4j
@Api(tags = "线下订单相关接口")
public class OrdersEmployeeController {
    /**
     * 服务对象
     */
    @Resource
    private OrdersEmployeeService ordersEmployeeService;

    //下单
    @PostMapping("/submit")
    @ApiOperation("下单")
    public Result submit(@RequestBody OrdersEmployeeDTO ordersEmployeeDTO){
        log.info("下单:{}",ordersEmployeeDTO);
        Result result = ordersEmployeeService.submit(ordersEmployeeDTO);
        return result;
    }

    //订单查询
    @GetMapping("/page")
    @ApiOperation("订单分页查询")
    public Result page(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("线下订单分页查询：{}",ordersPageQueryDTO);
        Result result = ordersEmployeeService.page(ordersPageQueryDTO);
        return result;
    }

    //退款
    @PostMapping("/refund")
    @ApiOperation("退款")
    public Result refund(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单:{}",ordersRejectionDTO);
        Result result = ordersEmployeeService.rejection(ordersRejectionDTO);
        return result;
    }


    //订单修改
    @PutMapping()
    @ApiOperation("修改订单")
    public Result update(@RequestBody OrdersEmployee ordersEmployee){
        log.info("修改订单：{}",ordersEmployee);
        OrdersEmployee ordersEmployee1 = ordersEmployeeService.update(ordersEmployee);
        if(ordersEmployee1 == null)
            return Result.error("修改失败");
        else
            return Result.success(ordersEmployee1);
    }

    //根据id查询订单

    @GetMapping("/{id}")
    @ApiOperation("根据id查询订单")
    public Result queryById(@PathVariable Long id){
        log.info("根据id查询订单:{}",id);
        Result result = ordersEmployeeService.detailById(id);
        return result;
    }

}

